package com.example.composableexample

import android.app.Application
import android.app.Service
import android.content.ComponentName
import android.content.Intent
import android.content.ServiceConnection
import android.os.Binder
import android.os.IBinder
import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewmodel.compose.viewModel

/**
 * author: LiLiang
 * createTime: 2022/9/27-22:27
 * remark:
 **/

@Preview
@Composable
fun ServiceViewModelScreen() {
    viewModel<ServiceViewModel>()
}

class ServiceViewModel(application: Application): AndroidViewModel(application) {
    init {
        Log.d("TAG", "viewModel Started: ")
        val intent = Intent(application, MyService::class.java)
        application.startService(intent)
    }
}

class MyService : Service() {
    override fun onCreate() {
        super.onCreate()
        Log.d("TAG", "Service  onCreate: ")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d("TAG", "Service onDestroy: ")
    }

    override fun onBind(intent: Intent?): IBinder? {
        TODO("Not yet implemented")
    }
}
